#include "arg.h"

void arg(int argc, char** argv, int &n, int &k)
{
    struct option longopts[] =  {
         {"number", required_argument, 0, 'n'},
         {"bit",    required_argument, 0, 'b'},
         {"help",   no_argument,       0, 'h'},
         {0, 0, 0, 0}
    };
    int c;
    while ((c = getopt_long(argc, argv, "-:n:b:W;", longopts, 0)) != -1)
        switch (c)  {
        case 'n':
            n = atoi(optarg);
            break;
        case 'b':
            k = atoi(optarg);
            break;
        case 'h':
            help();
            exit(0);
            break;
        case 1:
            cerr << argv[0] << ": argument " << optarg
            << " is unrecognized." << endl;
            cerr << "Try '" << argv[0]
            << " --help' for more information." << endl;
            exit(1);
            break;
        case ':':
            cerr << argv[0] << ": option -" << (char)optopt
            << " requires an argument." << endl;
            cerr << "Try '" << argv[0]
            << " --help' for more information." << endl;
            exit(1);
            break;
        case '?':
        default:
            cerr << argv[0] << ": option -" << (char)optopt
            << " is invalid." << endl;
            cerr << "Try '" << argv[0]
            << " --help' for more information." << endl;
            exit(1);
            break;
        }
    if (n <= 0) {
        cerr << argv[0] << ": number must be positive value" << endl;
        cerr << "Try '" << argv[0] << " --help' for more information." << endl;
        exit(1);
    } else if (k <= 0) {
        cerr << argv[0] << ": qbit must be positive value" << endl;
        cerr << "Try '" << argv[0] << " --help' for more information." << endl;
        exit(1);
    } else if (k > n) {
        cerr << argv[0] << ": qbit is less then number of state" << endl;
        cerr << "Try '" << argv[0] << " --help' for more information." << endl;
        exit(1);
    }
}

void help(void)
{
    cout << "No help for you!!! Hahahahah!!!" << endl;
}
